package com.Web.Service.Impl;

import com.Web.DAO.ICourseDAO;
import com.Web.DAO.Impl.CourseDAOImpl;
import com.Web.Person.Course;
import com.Web.Service.ICourseService;
import com.Web.util.PageInfo;

import java.util.List;

public class CourseServiceImpl implements ICourseService {

    private ICourseDAO courseDAO = new CourseDAOImpl();

    @Override
    public PageInfo<Course> selectByPage(Integer pageNo, Integer pageSize) {
        int offset = (pageNo - 1) * pageSize;
        List<Course> list = courseDAO.selectByPage(offset,pageSize);
        int totalCount = courseDAO.selectTotalCount();
        int totalPage = (int)Math.ceil((double)totalCount / pageSize);
        PageInfo<Course> pageInfo = new PageInfo<>(list, totalPage, pageNo, pageSize);
        return pageInfo;
    }

    @Override
    public List<Course> selectAll() {
        List<Course> list = courseDAO.selectAll();
        return list;
    }

    @Override
    public void add(Course course) {
        courseDAO.add(course);
    }

    @Override
    public void deleteById(int id) {
        courseDAO.deleteById(id);
    }

    @Override
    public Course toUpdate(int id) {
        Course course = courseDAO.toUpdate(id);
        return course;
    }

    @Override
    public void update(Course course) {
        courseDAO.update(course);
    }
}
